<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>活动管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="../../../static/images/favicon.ico" th:href="@{/images/favicon.ico}">
    <link rel="stylesheet" href="../../../static/plugin/layui/css/layui.css" th:href="@{/plugin/layui/css/layui.css}" media="all" />
    <link rel="stylesheet" href="../../../static/back_css/public.css" th:href="@{/back_css/public.css}" media="all" />
    <link rel="stylesheet" href="../../../static/back_css/activity_management.css" th:href="@{/back_css/activity_management.css}" media="all">
</head>
<body>
<div id="main">
    <div class="container">
        <div class="container_top">
            <ul>
                <li>
                    <input type="text" id="searchText" th:value="${name}"  name="name" placeholder="请输入关键字">
                    <a href="#" id="serach"> </a>
                </li>
                <li>
                    <div class="layui-input-inline clear">
                        <select id="modules" name="modules" lay-verify="required" lay-search="">
                            <option value="">活动状态</option>
                            <option value="1">进行中</option>
                            <option value="2">已结束</option>
                            <option value="0">未开始</option>
                        </select>
                    </div>
                </li>
                <li>
                    <button style="width: 45px;height: 25px;" class="search_btn layui-btn layui-btn-xs layui-bg-orange" onclick="searchName()" id="search">查询
                    </button>
                </li>
                <li><button class=" layui-bg-orange" onclick="create()" type="button" >创建活动</button></li>
            </ul>
        </div>
        <div id="activities" class="container_content">
            <ul>
                <li th:each="allActivity:${allActivity.list}">
                    <div>
                        <img src="../../images/bill.png" th:src="${allActivity.ACTIVITY_IMG}">
                        <div class="active" th:if="${allActivity.ACTIVITY_STATE}==1"></div>
                        <div class="end" th:if="${allActivity.ACTIVITY_STATE}==2"></div>
                        <div class="no_start" th:if="${allActivity.ACTIVITY_STATE}==0"></div>
                    </div>
                    <div>
                        <h4 th:text="${#strings.abbreviate(allActivity.ACTIVITY_NAME,12)}">第一届全民阅读活动</h4>
                        <p th:text="'活动主题：'+${allActivity.ACTIVITY_TOPIC}"></p>
                        <p>
                            活动类型：
                            <span th:switch="${allActivity.ACTIVITY_TYPE}">
                                <th:block th:case="0">线上</th:block>
                                <th:block th:case="1">线下</th:block>
                                <th:block th:case="2">线上+线下</th:block>
                                <th:block th:case="*">未知</th:block>
                            </span>
                        </p>
                        <p th:text="'主办单位：'+${allActivity.ZBDW}"></p>
                        <p th:text="'发布时间：'+${allActivity.CREATE_TIME}"></p>
                        <p th:if="${allActivity.STAGE_IS_OPEN}==0" th:text="'决赛：'+${allActivity.STARTTIME}+'--'+${allActivity.ENDTIME}">初赛：2019-06-06 -- 2019-07-10</p>
                        <p th:if="${allActivity.STAGE_1ST_NAME!=null}" th:text="${allActivity.STAGE_1ST_NAME}+':'+${allActivity.ST1_STARTTIME}+'--'+${allActivity.ST1_ENDTIME}">初赛：2025-01-01 -- 2025-12-31</p>
                        <p th:if="${allActivity.STAGE_2ND_NAME!=null}" th:text="${allActivity.STAGE_2ND_NAME}+':'+${allActivity.ST2_STARTTIME}+'--'+${allActivity.ST2_ENDTIME}">初赛：2025-01-01 -- 2025-12-31</p>
                        <p th:if="${allActivity.STAGE_3RD_NAME!=null}" th:text="${allActivity.STAGE_3RD_NAME}+':'+${allActivity.ST3_STARTTIME}+'--'+${allActivity.ST3_ENDTIME}">初赛：2025-01-01 -- 2025-12-31</p>
                        <p th:if="${allActivity.STAGE_4TH_NAME!=null}" th:text="${allActivity.STAGE_4TH_NAME}+':'+${allActivity.ST4_STARTTIME}+'--'+${allActivity.ST4_ENDTIME}">初赛：2019-06-06 -- 2019-07-10</p>
                    </div>
                    <div>
                        <div style="width: 50%;height: 100%;border: 1px solid #dad1d1; border-top: none; border-left: none;border-right: none;">
                            <a href="javascript:void(0)" th:onclick="|javascript:getActivityDetails( '${allActivity.ACTIVITY_ID}' )|"
                                style="display: block;width: 100%;height: 100%;color: rgb(0, 255, 85)">活动详情</a>
                        </div>
                        <div style="width: 50%;height: 100%;border: 1px solid #dad1d1;border-top: none;border-right: none;">
                            <a href="javascript:void(0)" th:onclick="|javascript:getSignInfo( '${allActivity.ACTIVITY_ID}' )|"
                                style="display: block;width: 100%;height: 100%;color: rgb(0, 174, 255)">报名管理</a>
                        </div>
                        <div style="width: 50%;height: 100%;border: 1px solid #dad1d1;border-top: none;border-right: none;">
                            <a href="javascript:void(0)" th:onclick="|javascript:getStatInfo( '${allActivity.ACTIVITY_ID}' )|"
                                style="display: block;width: 100%;height: 100%;color: rgb(255, 123, 0)">活动统计</a>
                        </div>
                        <div style="width: 50%;height: 100%;border: 1px solid #dad1d1;border-top: none;border-right: none;">
                            <a href="javascript:void(0)" th:onclick="|javascript:getComments( '${allActivity.ACTIVITY_ID}' )|"
                                style="display: block;width: 100%;height: 100%;color: rgb(187, 0, 255)">评论管理</a>
                        </div>
                        <div th:if="${admin_id}==${allActivity.ADMIN_ID} or ${isSup}==1"
                            style="width: 50%;height: 100%;border: 1px solid #dad1d1; border-top: none;border-right: none;">
                            <a href="javascript:void(0)" th:onclick="|javascript:deleteActivity( '${allActivity.ACTIVITY_ID}' )|"
                                style="display: block;width: 100%;height: 100%;color: red">删除</a>
                        </div>
                    </div>
                </li>
                <div class="clear"></div>
            </ul>
            <input type="hidden" th:value="${allActivity.getSize()}" id="size"/>
        </div>
        <div class="container_footer" id="demo7"></div>
    </div>
</div>

<script type="text/html" id="activity_item">
    <li>
        <div>
            <img  src="">
            <span><a href=""></a></span>
        </div>
        <div>
            <h4></h4>
            <p></p>
            <p></p>
            <p></p>
        </div>
        <div>
            <a href="">编辑</a>
            <a href="">详情</a>
        </div>
    </li>
</script>
<script type="text/javascript" src="../../../static/plugin/layui/layui.js" th:src="@{/plugin/layui/layui.js}"></script>
<script type="text/javascript">
    var $;
    var layer = null

    function getActivityDetails(id){
        $.ajax({//进行审核提交
            url: '/getIndexAl',
            async: false,
            type: "POST",
            data: {
                ACTIVITY_ID:id
            },
            success: function (data) {
                window.parent.setActivityInfo(data.activity_NAME,data.starttime+'-'+data.endtime,data.activity_STATE);
                window.parent.gotoActivityDetail();
                window.location.href='/getActivityDetails';
            }
        })
    }
    function getSignInfo(id){
        $.ajax({//进行审核提交
            url: '/getIndexAl',
            async: false,
            type: "POST",
            data: {
                ACTIVITY_ID: id
            },
            success: function (data) {
                window.location.href = '/signup_info';
            }
        })
    }
    function getStatInfo(id){
        $.ajax({//进行审核提交
            url: '/getIndexAl',
            async: false,
            type: "POST",
            data: {
                ACTIVITY_ID: id
            },
            success: function (data) {
                window.location.href = '/accountWorkDetails';
            }
        })
    }
    function getComments(id){
        $.ajax({//进行审核提交
            url: '/getIndexAl',
            async: false,
            type: "POST",
            data: {
                ACTIVITY_ID: id
            },
            success: function (data) {
                window.location.href = '/evaluate';
            }
        })
    }

    function deleteActivity(id){
        var size = $("#size").val();
        if(size==1){
            layer.confirm('该活动是最后一个活动，删除该活动可能会导致该活动下的作品无法访问，删除该活动后将会重新定位到登录页面，请谨慎删除！', {icon: 3, title:'提示'}, function(index){
                $.ajax({//进行审核提交
                    url: '/deleteActivity',
                    async: false,
                    type: "POST",
                    data: {
                        ACTIVITY_ID:id
                    },
                    success: function (data) {
                        if(data==1){
                            // layer.msg("删除成功！")
                            layer.msg("删除成功!")
                            time: 3000
                        }else{
                            layer.msg("删除失败！")
                            time: 3000
                        }
                        setTimeout(function(){window.parent.location.href='/exit';},500)
                    }
                })
            },function (index) {
                layer.close(index);
            })
        }else {
            layer.confirm('删除该活动可能会导致该活动下的作品无法访问，请谨慎删除！', {icon: 3, title:'提示'}, function(index){
                $.ajax({//进行审核提交
                    url: '/deleteActivity',
                    async: false,
                    type: "POST",
                    data: {
                        ACTIVITY_ID:id
                    },
                    success: function (data) {
                        if(data==1){
                            // layer.msg("删除成功！")
                            layer.msg("删除成功!")
                            time: 3000
                        }else{
                            layer.msg("删除失败！")
                            time: 3000
                        }
                        setTimeout(function(){window.location.href='/getAllActivity';},500)
                    }
                })
            },function (index) {
                layer.close(index);
            })
        }
    }

    function searchName(){
        var name = $("#searchText").val();
        var state = $("#modules").val();
        window.location.href="/getAllActivity?name="+name+"&state="+state
    }

    function create(){
        window.location.href='/create_activity';
    }

    var totalcords = "[[${allActivity.total}]]";
    var currentPage = "[[${allActivity.pageNum}]]";
    layui.use(['laypage', 'layer'], function() {
        var laypage = layui.laypage;
            layer = layui.layer;
            $=layui.jquery;
        function getDataFromServer(pageNum,limit){
            $.post({
                url:"/getAllActivity1",
                data:{
                    pageNum:pageNum,
                    limit:limit
                },
                success(res){
                    res=[
                        {
                            id:1,
                            title:"读书活动",
                            img:"",
                            state:1
                        },
                        {
                            id:2,
                            title:"全民阅读",
                            img:"",
                            state:1
                        },
                    ]
                        $("#activities").empty();
                        $("#activities").append("<ul></ul>");
                        $.each(res,function(index,obj){
                        });
                },
                error(res){
                }
            })
        }

        laypage.render({
            elem: 'demo7'
            ,count: parseInt(totalcords)
            ,limit:10
            ,curr:parseInt(currentPage)
            , jump: function (obj,first) {
                if(!first){
                   window.location.href="/getAllActivity?limit="+obj.limit+"&page="+obj.curr;
                }
            }
        });
    })
</script>
</body>
</html>